﻿// 功能：文本框控件基类
// 描述：
// 作者：温伟鹏
// 日期：2010/11/1 15:14:12

using System;
using System.Collections.Generic;
using System.Text;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 文本框控件基类
    /// </summary>
    public abstract class TextBoxBase : Control
    {
        #region 事件
        /// <summary>
        /// 当文本框获得焦点后触发此事件
        /// </summary>
        public event FocusedEventHandler Focused;
        /// <summary>
        /// 当文本框失去焦点后触发此事件
        /// </summary>
        public event LostFocusEventHandler LostFocus;
        #endregion

        #region 公共属性
        /// <summary>
        /// 获取或设置设置文本框提示消息
        /// </summary>
        public virtual string Tip
        {
            get;
            set;
        }
        /// <summary>
        /// 获取或设置编辑框左侧无效区域宽度
        /// </summary>
        public virtual int LeftInvalidOffset
        {
            get;
            set;
        }
        /// <summary>
        /// 获取或设置编辑框右侧无效区域宽度
        /// </summary>
        public virtual int RightInvalidOffset
        {
            get;
            set;
        }
        #endregion

        #region 函数
        /// <summary>
        /// 控件获取焦点后触发Focused事件
        /// </summary>
        /// <param name="pObj"></param>
        internal void InternalOnFocused(IntPtr pObj)
        {
            Control ctr = Control.FromHandle(pObj);

            FocusedEventArgs e = new FocusedEventArgs(ctr);

            OnFocused(e);
        }
        /// <summary>
        /// 控件失去焦点后触发LostFocus事件
        /// </summary>
        /// <param name="pObj"></param>
        internal void InternalOnLostFocus(IntPtr pObj)
        {
            Control ctr = Control.FromHandle(pObj);

            LostFocusEventArgs e = new LostFocusEventArgs(ctr);

            OnLostFocus(e);
        }
        /// <summary>
        /// 触发Focused事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnFocused(FocusedEventArgs e)
        {
            if (Focused != null)
                Focused(this, e);
        }
        /// <summary>
        /// 触发LostFocus事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnLostFocus(LostFocusEventArgs e)
        {
            if (LostFocus != null)
                LostFocus(this, e);
        }
        #endregion
    }
}
